/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-02-28
 * Time: 17:58
 */

public class Segregation2 {
    public static void main(String[] args) {
        //使用
        A1 a = new A1();
        a.depend1(new B1());
        a.depend2(new B1());
        a.depend3(new B1());

        C1 c1 = new C1();
        c1.depend1(new D1());
        c1.depend4(new D1());
        c1.depend5(new D1());
    }
}

// 对接口 进行拆分 实现 接口隔离原则
interface Interface11{
    void operation1();
}

interface Interface2{
    void operation2();
    void operation3();
}

interface Interface3{
    void operation4();
    void operation5();
}

//实现 B D类
class B1 implements Interface11,Interface2{
    @Override
    public void operation1() {
        System.out.println("B 实现了 operation1");
    }

    @Override
    public void operation2() {
        System.out.println("B 实现了 operation2");
    }

    @Override
    public void operation3() {
        System.out.println("B 实现了 operation3");
    }
}

class D1 implements Interface11,Interface3{
    @Override
    public void operation1() {
        System.out.println("D 实现了 operation1");
    }

    @Override
    public void operation4() {
        System.out.println("D 实现了 operation4");
    }

    @Override
    public void operation5() {
        System.out.println("D 实现了 operation5");
    }
}

// A 类通过 接口 interface1 依赖(使用) B类 但是 也只会使用到1，2，3方法
class A1{
    public void depend1(Interface11 i){
        i.operation1();
    }
    public void depend2(Interface2 i){
        i.operation2();
    }
    public void depend3(Interface2 i){
        i.operation3();
    }



}

// C 类 通过接口 Interface1 依赖 使用D类 但是只会使用到 1，4，5方法
class C1{
    public void depend1(Interface11 i){
        i.operation1();
    }
    public void depend4(Interface3 i){
        i.operation4();
    }
    public void depend5(Interface3 i){
        i.operation5();
    }
}